home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World Komputer 2010 April
/
PCWorld0410.iso
/
pluginy Firefox
/
50550
/
50550.xpi
/
chrome
/
clickabilitydeveloper.jar
/
content
/
clickabilitydeveloper.js
next >
Wrap
Text File
|
2010-01-14
|
10KB
|
251 lines
var ClickabilityDeveloper_NewWindow = null;
var ClickabilityDeveloper_DebugParameter = "debug";
var ClickabilityDeveloper_HelpParameter = "showHelp";
var ClickabilityDeveloper_DebugModes = new Array("basic","extended","full");
var ClickabilityDeveloper_DebugMode = "basic";
window.addEventListener("load", ClickabilityDeveloper_Initialize, false);
// Initializes the extension
function ClickabilityDeveloper_Initialize(event)
{
document.getElementById("ClickabilityDeveloper-basicDebug-Menu").setAttribute("checked","checked");
document.getElementById("ClickabilityDeveloper-basicDebug-Menu").setAttribute("checked","true");
}
////////////////////////////////////////////////////////////////////////////////
// The ClickabilityDeveloper_CacheBust() function performs a cache-bust on the page
////////////////////////////////////////////////////////////////////////////////
function ClickabilityDeveloper_CacheBust() {
var r = ClickabilityDeveloper_GetRandomString(8);
var url = new String(window._content.document.location);
var p = "abc";
var value = ClickabilityDeveloper_GetParamterValue(p);
if( value == "" ) {
if(url.indexOf("?")==-1) {
ClickabilityDeveloper_LoadURL(url+"?"+p+"="+r);
} else {
ClickabilityDeveloper_LoadURL(url+'&'+p+"="+r);
}
} else {
var newURL = url.replace(p+"="+value, p+"="+r);
ClickabilityDeveloper_LoadURL(newURL);
}
}
////////////////////////////////////////////////////////////////////////////////
// The ClickabilityDeveloper_Debug() function toggles debugging mode
////////////////////////////////////////////////////////////////////////////////
/*
function ClickabilityDeveloper_Debug() {
var url = new String(window._content.document.location);
var p = ClickabilityDeveloper_DebugParameter;
var value = ClickabilityDeveloper_GetParamterValue(p);
if( value == "" ) {
if(url.indexOf("?")==-1) {
ClickabilityDeveloper_LoadURL(url+"?"+p+"=y");
} else {
ClickabilityDeveloper_LoadURL(url+'&'+p+"=y");
}
} else {
if(value == "y") {
// Debug is already in the url, we reverse it to turn if off
var newURL = url.replace(p+"="+value, p+"=n");
} else {
var newURL = url.replace(p+"="+value, p+"=y");
}
ClickabilityDeveloper_LoadURL(newURL);
}
}
*/
function ClickabilityDeveloper_ChangeDebugMode(mode) {
ClickabilityDeveloper_DebugMode = mode.toLowerCase();
var url = new String(window._content.document.location);
var value = ClickabilityDeveloper_GetParamterValue(ClickabilityDeveloper_DebugParameter);
var i;
var newURL = '';
// Uncheck other modes
for (i in ClickabilityDeveloper_DebugModes) {
if(ClickabilityDeveloper_DebugMode == ClickabilityDeveloper_DebugModes[i]) {
/*
Make sure at least one debug mode is checked
*/
document.getElementById("ClickabilityDeveloper-"+ClickabilityDeveloper_DebugModes[i]+"Debug-Menu").setAttribute("checked","true");
} else if(ClickabilityDeveloper_DebugMode != ClickabilityDeveloper_DebugModes[i]) {
document.getElementById("ClickabilityDeveloper-"+ClickabilityDeveloper_DebugModes[i]+"Debug-Menu").setAttribute("checked","false");
}
}
if( value != "" ) {
if(url.indexOf("?"+ClickabilityDeveloper_DebugParameter+"&") > -1) {
newURL = url.replace(ClickabilityDeveloper_DebugParameter+"="+value, "?"+ClickabilityDeveloper_DebugParameter+"="+ClickabilityDeveloper_DebugMode);
} else if(url.indexOf("?"+ClickabilityDeveloper_DebugParameter) > -1) {
newURL = url.replace("?"+ClickabilityDeveloper_DebugParameter+"="+value, "?"+ClickabilityDeveloper_DebugParameter+"="+ClickabilityDeveloper_DebugMode);
}else {
newURL = url.replace("&"+ClickabilityDeveloper_DebugParameter+"="+value, "&"+ClickabilityDeveloper_DebugParameter+"="+ClickabilityDeveloper_DebugMode);
}
ClickabilityDeveloper_LoadURL(newURL);
}
}
function ClickabilityDeveloper_ToggleDebug() {
var url = new String(window._content.document.location);
var value = ClickabilityDeveloper_GetParamterValue(ClickabilityDeveloper_DebugParameter);
if( value == "" ) {
// Add parameter to url
if(url.indexOf("?")==-1) {
ClickabilityDeveloper_LoadURL(url+"?"+ClickabilityDeveloper_DebugParameter+"="+ClickabilityDeveloper_DebugMode);
} else {
ClickabilityDeveloper_LoadURL(url+'&'+ClickabilityDeveloper_DebugParameter+"="+ClickabilityDeveloper_DebugMode);
}
} else {
// Remove parameter from url
if(url.indexOf("?"+ClickabilityDeveloper_DebugParameter+"="+value+"&") > -1) {
newURL = url.replace(ClickabilityDeveloper_DebugParameter+"="+value+"&", "");
} else if(url.indexOf("?"+ClickabilityDeveloper_DebugParameter+"="+value) > -1) {
newURL = url.replace("?"+ClickabilityDeveloper_DebugParameter+"="+value, "");
} else {
newURL = url.replace("&"+ClickabilityDeveloper_DebugParameter+"="+value, "");
}
ClickabilityDeveloper_LoadURL(newURL);
}
}
////////////////////////////////////////////////////////////////////////////////
// The ClickabilityDeveloper_Environment() function changes the server environment
////////////////////////////////////////////////////////////////////////////////
function ClickabilityDeveloper_Environment(env) {
var host = ClickabilityDeveloper_GetHost();
var newURL = window._content.document.location.protocol + "//" + env + host + window._content.document.location.pathname + window._content.document.location.search;
ClickabilityDeveloper_LoadURL(newURL);
}
////////////////////////////////////////////////////////////////////////////////
// The ClickabilityDeveloper_GetHost() function extracts the domain from the URL
////////////////////////////////////////////////////////////////////////////////
function ClickabilityDeveloper_GetHost() {
/*
Original code
var domain = window._content.document.location.host;
var tldPos = domain.lastIndexOf(".");
var hostPos = domain.lastIndexOf(".",tldPos-1);
return domain.substring(hostPos+1);
Rewritten by Noach Magedman <nmagedman@aish.com> to handle multiple subdomains
e.g. www.foo.co.il or www.foo.bar.com
*/
var host = window._content.document.location.host;
var domainPos = host.indexOf("www.") + 4;
return host.substring(domainPos);
}
////////////////////////////////////////////////////////////////////////////////
// The ClickabilityDeveloper_GetParamterValue() function gets a URL parameter's value
////////////////////////////////////////////////////////////////////////////////
function ClickabilityDeveloper_GetParamterValue(name) {
name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
var regexS = "[\\?&]"+name+"=([^]*)";
var regex = new RegExp( regexS );
var results = regex.exec( window._content.document.location );
if( results == null ) {
return "";
} else {
return results[1];
}
}
////////////////////////////////////////////////////////////////////////////////
// The ClickabilityDeveloper_GetRandomString() function generates a random alphanumeric string
////////////////////////////////////////////////////////////////////////////////
function ClickabilityDeveloper_GetRandomString(strlength) {
var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";
var randomstring = '';
for (var i=0; i<strlength; i++) {
var rnum = Math.floor(Math.random() * chars.length);
randomstring += chars.substring(rnum,rnum+1);
}
return randomstring;
}
////////////////////////////////////////////////////////////////////////////////
// The ClickabilityDeveloper_Help() function turns on help mode
////////////////////////////////////////////////////////////////////////////////
/* Old function
function ClickabilityDeveloper_Help() {
var url = new String(window._content.document.location);
var p = "showHelp";
var value = ClickabilityDeveloper_GetParamterValue(p);
if( value == "" ) {
if(url.indexOf("?")==-1) {
ClickabilityDeveloper_LoadURL(url+"?"+p+"=y");
} else {
ClickabilityDeveloper_LoadURL(url+'&'+p+"=y");
}
} else {
if(value == "y") {
// Debug is already in the url, we reverse it to turn if off
var newURL = url.replace(p+"="+value, p+"=n");
} else {
var newURL = url.replace(p+"="+value, p+"=y");
}
ClickabilityDeveloper_LoadURL(newURL);
}
}
*/
function ClickabilityDeveloper_Help() {
var url = new String(window._content.document.location);
var value = ClickabilityDeveloper_GetParamterValue(ClickabilityDeveloper_HelpParameter);
if( value == "" ) {
// Add parameter to url
if(url.indexOf("?")==-1) {
ClickabilityDeveloper_LoadURL(url+"?"+ClickabilityDeveloper_HelpParameter+"=y");
} else {
ClickabilityDeveloper_LoadURL(url+'&'+ClickabilityDeveloper_HelpParameter+"=y");
}
} else {
// Remove parameter from url
if(url.indexOf("?"+ClickabilityDeveloper_HelpParameter+"="+value+"&") > -1) {
newURL = url.replace(ClickabilityDeveloper_HelpParameter+"="+value+"&", "");
} else if(url.indexOf("?"+ClickabilityDeveloper_HelpParameter+"="+value) > -1) {
newURL = url.replace("?"+ClickabilityDeveloper_HelpParameter+"="+value, "");
} else {
newURL = url.replace("&"+ClickabilityDeveloper_HelpParameter+"="+value, "");
}
ClickabilityDeveloper_LoadURL(newURL);
}
}
////////////////////////////////////////////////////////////////////////////////
// The ClickabilityDeveloper_LoadURL() function loads the specified URL in the browser.
////////////////////////////////////////////////////////////////////////////////
function ClickabilityDeveloper_LoadURL(url) {
// Set the browser window's location to the incoming URL
window._content.document.location = url;
// Make sure that we get the focus
window.content.focus();
}
////////////////////////////////////////////////////////////////////////////////
// The ClickabilityDeveloper_Login() function launches the CMS login pop-up window
////////////////////////////////////////////////////////////////////////////////
function ClickabilityDeveloper_Login(url) {
if(ClickabilityDeveloper_NewWindow == null || ClickabilityDeveloper_NewWindow.closed) {
// Window does not exist, open new window
ClickabilityDeveloper_NewWindow = window.open(url,'ClickabilityTB_Window','title=yes,location=no,scrollbars=yes,menubar=no,toolbar=no,resizable=yes,status=yes,width=1015');
} else {
// Window is already open, focus window
ClickabilityDeveloper_NewWindow.focus();
}
}